package org.example.mapper;

import org.apache.ibatis.annotations.*;
import org.example.common.entity.Carousel;

import java.util.List;

@Mapper
public interface CarouselMapper {

    // 插入一条轮播图记录
    @Insert("INSERT INTO carousel (image_url, link_url, title, description, sort, status, start_time, end_time, is_deleted, created_by, updated_by, platform) " +
            "VALUES (#{imageUrl}, #{linkUrl}, #{title}, #{description}, #{sort}, #{status}, #{startTime}, #{endTime}, #{isDeleted}, #{createdBy}, #{updatedBy}, #{platform})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Carousel carousel);

    // 根据 ID 更新轮播图记录
    @Update("UPDATE carousel SET image_url = #{imageUrl}, link_url = #{linkUrl}, title = #{title}, description = #{description}, sort = #{sort}, status = #{status}, " +
            "start_time = #{startTime}, end_time = #{endTime}, is_deleted = #{isDeleted}, updated_by = #{updatedBy}, platform = #{platform} " +
            "WHERE id = #{id}")
    int updateById(Carousel carousel);

    // 根据 ID 删除轮播图记录（逻辑删除）
    @Update("UPDATE carousel SET is_deleted = 1 WHERE id = #{id}")
    int deleteById(Long id);

    // 根据 ID 查询轮播图记录
    @Select("SELECT * FROM carousel WHERE id = #{id} AND is_deleted = 0")
    Carousel selectById(Long id);

    // 查询所有未删除的轮播图记录
    @Select("SELECT * FROM carousel WHERE is_deleted = 0")
    List<Carousel> selectAll();

    // 根据平台和状态查询轮播图记录
    @Select("SELECT * FROM carousel WHERE platform = #{platform} AND status = #{status} AND is_deleted = 0 ORDER BY sort DESC")
    List<Carousel> selectByPlatformAndStatus(@Param("platform") String platform, @Param("status") Integer status);
}